<?php
//$debug=1;
require './googlechartphplib-0.5/lib/GoogleChart.php';
require './googlechartphplib-0.5/lib/GoogleBarChart.php';
//get data
$db_obj = mysql_connect('localhost', 'smatool', 'warming') or die(mysql_error());
$qrymax=0;
$qrystep=0;
$city_data_colors="";
$city_data_label="";

    
mysql_select_db('local_data', $db_obj);

function imp($char,$tag){
	foreach($char as $key=>$value){
	$char[$key] = $value;
	}
	$char = implode($tag,$char);
	return $char;
}

	$sql = 'select sum(CurrentPower)*(5/60) as DayYield from DayData where DateTime >= now() - interval 1 year group by month(DateTime)';

	$query = mysql_query($sql);
	while($row = mysql_fetch_array($query)){
	//$date[] = $row['DateTime'];
	$data[] = $row['DayYield'];

	}
	
	$sql='SELECT distinct month(DateTime) as dHour FROM DayData WHERE DateTime >= NOW() - interval 1 year';
	$query = mysql_query($sql);
	while($row = mysql_fetch_array($query)){
	$date[] = $row['dHour'];
	}

$chart= new GoogleBarChart('bvs', 500, 200);
//$chart->setAutoscale(GoogleChart::AUTOSCALE_VALUES);
$chart->setAutoscale(GoogleChart::AUTOSCALE_OFF);
$chart->setGridLines(100,11.11);

$line = new GoogleChartData($data);
$chart->addData($line);
$chart->setScale(0,540000);
$chart->setBarWidth('a');

$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawLine(true);
$y_axis->setDrawTickMarks(true);
$y_axis->setLabels(array(null,60000,120000,180000,240000,300000,360000,420000,480000,540000));
$y_axis->setFontSize(9);
$y_axis->setTickMarks(5);
//$y_axis->setTickColor('ffffff');
$chart->addAxis($y_axis);

$x_axis = new GoogleChartAxis('x');
$x_axis->setDrawLine(true);
$x_axis->setDrawTickMarks(false);
$x_axis->setLabels($date);
//$x_axis->setLabelPositions(0,25.8,51.8,77.6);
$x_axis->setTickMarks(5);
$x_axis->setFontSize(9);
$chart->addAxis($x_axis);

if ( isset($debug) ) {
	var_dump($chart->getQuery());
	echo $chart->validate();
	echo $chart->toHtml();
}
else{
	header('Content-Type: image/png');
	echo $chart;
}
